<template>
	<view class="selectFactory">
		<!-- <view class="title disFlex">
			<view class="left">选择中标工厂</view>
			<view class="right">
				<text class="name">工厂名称</text>
				<text class="iconfont icon-jiantoushangxiao"></text>
			</view>
		</view>
		<view class="list disFlex scale-1px-bottom" v-for="(item,index) in factorys" :key='index'>
			<view class="info">
				<text class="iconfont icon-not_Selected-copy"></text>
				<text class="name">{{item.factory.factory_name}}</text>
			</view>
			<view class="right" style="color: #2291FF;" @tap="getnav(router(`factoryDetail?id=${item.factory.id}`))">查看</view>
		</view> -->
		<!-- <view class="title disFlex">
			<picker  @change="changeBirth">
				<view class="box disFlex scale-1px-bottom ">
					<view class="left">
					<view class="word">选择备选工厂</view>
					</view>
					<view class="right">
						<text class="name">工厂名称</text>
					</view>
				</view>
			</picker>
		</view> -->
		<uni-collapse>
			<uni-collapse-item title="选择中标工厂">
				<uni-list>
					<checkbox-group @change="selfactory($event,1)">
						<view class="list disFlex scale-1px-bottom" v-for="(item,index) in factorys" :key='index'>
							<view class="info">
								<checkbox :value="item.factory_id"/>
								<text class="name">{{item.factory.factory_name}}</text>
							</view>
							<view class="right" style="color: #2291FF;" @tap="getnav(router(`factoryDetail?id=${item.factory.id}`))">查看</view>
						</view>
					</checkbox-group>
				</uni-list>
			</uni-collapse-item>
			<uni-collapse-item title="选择备选工厂">
				<checkbox-group @change="selfactory($event,2)">
					<view class="list disFlex scale-1px-bottom" v-for="(item,index) in factorys" :key='index'>
						<view class="info">
							<checkbox :value="item.factory_id"  />
							<text class="name">{{item.factory.factory_name}}</text>
						</view>
						<view class="right" style="color: #2291FF;" @tap="getnav(router(`factoryDetail?id=${item.factory.id}`))">查看</view>
					</view>
				</checkbox-group>
			</uni-collapse-item>
		</uni-collapse>



		<view class="bottom">
			<button @tap="begin">选中开标</button>
		</view>
	</view>
</template>

<script>
	import uniCollapse from '@/components/uni-collapse/uni-collapse.vue'
	import uniCollapseItem from '@/components/uni-collapse-item/uni-collapse-item.vue'
	export default {
		components: {
			uniCollapse,
			uniCollapseItem
		},
		data() {
			return {
				id:'',
				factorys: [],
				main: [],
				standby: [],
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getfactory(this.id)
		},
		methods: {
			getfactory(id) {
				this.http('/api/tender_order/lists', 'post', {
						id
					}, )
					.then((res) => {
						this.factorys = res.data
						console.log(this.factorys)
					})
			},
			selfactory(e,i) {
				if (i == 1) {
					this.main=e.detail.value
				}else{
					this.standby=e.detail.value
				}
				console.log(this.main,this.standby)
			},
			begin() {
				uni.showModal({
					title: '提示',
					content: '是否确认您选择的中标厂家？',
					confirmText: '确定开标',
					confirmColor: "#2291FF",
					cancelColor: "#BEC9D7",
					success: (e) => {
						if (e.confirm) {
							this.open()
						}
					}
				})
			},
			open(){
				let data={
					id:this.id,
					main:this.main.toString(','),
					standby:this.standby.toString(','),
				}
				this.http('/api/tender_order/open', 'post',data, )
					.then((res) => {
						console.log(res)
						if(res.sta==200){
							this.getnav(this.router(`myCustomized?type=1`))
							uni.showToast({
								title:'开标成功',
								icon:'none'
							})
						}else{
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
						}
					})
			}
		}
	}
</script>

<style lang="less">
	.uni-collapse-cell--open.data-v-8f47561c {
		background-color: #fff !important;

	}

	checkbox .wx-checkbox-input {
		border-radius: 50%;
	}

	checkbox .wx-checkbox-input.wx-checkbox-input-checked {
		border: 1px solid #007AFF;
		background: #007AFF;
		color: #fff !important;
	}

	.selectFactory {
		padding: 0 40rpx;
		padding-bottom: 100rpx;

		.title {
			padding: 35rpx 0 25rpx 0;

			.left {
				font-size: 32rpx;
			}

			.right {
				.name {
					color: #BEC9D7;
					font-size: 30rpx;
				}
			}
		}

		.list {
			padding: 35rpx 0;

			.info {
				display: flex;
				align-items: center;

				.name {
					padding-left: 20rpx;
				}
			}

			.text {
				color: #2291FF;
			}
		}

		.bottom {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 90rpx;
			padding: 0 40rpx;
			z-index: 99;

			button {
				width: 100%;
				line-height: 90rpx;
				background: rgba(34, 145, 255, 1) !important;
				border-radius: 10rpx;
				color: #fff;
				font-size: 32rpx;
			}
		}
	}
</style>
